﻿using System;
using System.Collections.Generic;
 
using System.Windows.Forms;
using System.Threading;

namespace Skipette
{
    public static class Program
    {
        public static bool exiting = false;
        public static Startup st;
        public static Account currentProfile;
        public static String pass;
        public static STATUS currentStatus = STATUS.OFFLINE;
        public static List<Category> categories = new List<Category>();
        public static List<Account> contacts = new List<Account>();
        public static List<Conversation> conversations = new List<Conversation>();

        //SETTINGS
        public static bool compact = false;
        public static String lastUsername;
        public static String lastPass;
        public static bool remember;
        public static List<CashedInfo> cache = new List<CashedInfo>();

        public enum STATUS
        { ONLINE, BUSY, HIDDEN, OFFLINE }

        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Server.InitializeListener();
            Application.Run(st = new Startup());
        }

        public static STATUS StatusFromString(String status)
        {
            if (status.Equals("Online"))
                return STATUS.ONLINE;
            else if (status.Equals("Busy"))
                return STATUS.BUSY;
            else if (status.Equals("Hidden"))
                return STATUS.HIDDEN;
            else
                return STATUS.OFFLINE;
        }

        public static Account LogIn(String username, String pass, STATUS desiredStatus)
        {
            if (Server.Authenticate(username, pass))
            {
                currentProfile = Server.GetAccount(username);
                contacts = currentProfile.friends; //TO REVISE!!!
                currentStatus = desiredStatus;
            }
            return currentProfile;
        }

        public static void LogOut()
        {
            Program.currentProfile = null;
            Program.currentStatus = Program.STATUS.OFFLINE;
            st.Logout();
        }

        public static void OnDisconnect()
        {

        }

        public static bool TestServer()
        {
            //DUMMY
            Thread.Sleep(3000);
            return true;
        }
    }
}
